﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Test_LYK.DataAccess;
using Test_LYK.Models;

namespace Test_LYK.Repository
{
    public class FoodReposiroty
    {
        public bool AddFood(string food)
        {
            var db = new EatEntities();

            db.Food.Add(new Food() { Food1 = food });

            return db.SaveChanges() > 0;
        }

        public bool ModifyFood(int id, string food)
        {
            var db = new EatEntities();
            var foodModify = db.Food.FirstOrDefault(s => s.Id == id);
            foodModify.Food1 = food;
            return db.SaveChanges() > 0;
        }

        public List<FoodModel> GetFoodList()
        {
            var db = new EatEntities();

            var foodList = db.Food.Select(s => new FoodModel() { Id = s.Id, Food = s.Food1 }).ToList();

            return foodList;
        }
    }
}